package com.orkasgb.framework.hadoop.mapperreduce.etl;

import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;
import java.util.regex.Pattern;

public class ETLMapper extends Mapper<LongWritable, Text, NullWritable, Text> {

    private Pattern pattern = Pattern.compile("^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$");

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        if (key.get() == 0) {
            return;
        }

        //姓名	电话	地址	备注
        //卡卡1	18688236529	****	****
        String[] split = value.toString().split("\t");
        if (split.length == 1 || StringUtils.isBlank(split[1]) || !pattern.matcher(split[1]).matches()) {
            return;
        }
        context.write(NullWritable.get(), value);
    }
}
